<?php
class Reply_model extends CI_Model {
	public function add_reply($uid,$pid,$content){
		$this->db->insert('reply',array(
				'uid'=>$uid,
				'pid'=>$pid,
				'content'=>$content,
				'replytime'=> date('Y-m-d H:i:s'),
			));
		return $this->db->insert_id();
	}
	
	public function get_reply($pid){
		$sql = 'select r.content as content,r.replytime as time,u.uname as author 
				from reply r join user u on r.uid = u.uid
				where r.pid = ?';
		$query = $this->db->query($sql,array($pid));
		return $query->result_array();
	}
	
	public function get_num_reply($pid){
		$this->db->where('pid',$pid-0);
		return $this->db->count_all_results("reply");
	}
	
}

?>